<?php
/**
 * Created by PhpStorm.
 * User: edmmss
 * Date: 2018/12/5
 * Time: 14:04
 */

namespace app\modules\flyweight;


class FlyweightFactory implements \Countable
{
    private $_pool = [];

    /**
     * 输入字符串格式数据 $name
     *
     * @date   2018/12/5
     * @author edmmss
     * @param string $name
     * @return CharacterFlyweight
     */
    public function get(string $name): CharacterFlyweight
    {
        if (!isset($this->_pool[$name])) {
            $this->_pool[$name] = new CharacterFlyweight($name);
        }

        return $this->_pool[$name];
    }

    /**
     * className
     *
     * @date   2018/12/5
     * @author edmmss
     * @return int
     */
    public function count(): int
    {
        // TODO: Implement count() method.
        return count($this->_pool);
    }
}